package main

import "fmt"
import "os"
import "math"

func isPrime(n int) bool {
	if n <= 1 {
		return false
	}
	var end int
	end = int(math.Sqrt(float64(n)))
	for i := 2; i <= end; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}
func WriteFile(path string) {
	f, err := os.Create(path)
	if err != nil {
		fmt.Println("打开文件异常")
		return
	}
	fmt.Println("输出判断到prime.txt....")
	for i := 2; i <= 500; i++ {
		//fmt.Println("i=", i)
		if isPrime(i) == true {
			buf := fmt.Sprintf("i=%d\n", i)
			f.WriteString(buf)
		}
	}
	fmt.Println("输出完毕")
	defer f.Close()
}
func main() {
	path := "../target/prime.txt"
	WriteFile(path)
}
